﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Cms.Core.Data.Migrations
{
    public partial class _20190317 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AuditLog",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    UserId = table.Column<Guid>(nullable: true),
                    ServiceName = table.Column<string>(type: "nchar(1000)", nullable: false),
                    MethodName = table.Column<string>(type: "nchar(1000)", nullable: false),
                    Parameters = table.Column<string>(type: "nvarchar(1500)", nullable: true),
                    ExecutionTime = table.Column<DateTime>(type: "datetime", nullable: true),
                    ExecutionDuration = table.Column<long>(type: "bigint", nullable: true),
                    ClientIPAddress = table.Column<string>(type: "nchar(15)", nullable: true),
                    ClientName = table.Column<string>(type: "nvarchar(50)", nullable: true),
                    BrowserInfo = table.Column<string>(type: "nchar(1000)", nullable: true),
                    ExceptionInfo = table.Column<string>(type: "nvarchar(MAX)", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(100)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AuditLog", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysModule",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    ParentId = table.Column<Guid>(nullable: true),
                    Name = table.Column<string>(type: "nvarchar(10)", nullable: false),
                    LinkUrl = table.Column<string>(type: "nchar(10)", nullable: false),
                    Area = table.Column<string>(type: "nchar(50)", nullable: true),
                    Controller = table.Column<string>(nullable: true),
                    Action = table.Column<string>(nullable: true),
                    Code = table.Column<string>(type: "nvarchar(20)", nullable: true),
                    OrderSort = table.Column<int>(nullable: false, defaultValue: 0),
                    Description = table.Column<string>(type: "nvarchar(1000)", nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false, defaultValue: true),
                    Parameter = table.Column<string>(type: "nvarchar(100)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysModule", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysPermission",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    Code = table.Column<string>(type: "nvarchar(10)", nullable: true),
                    Name = table.Column<string>(type: "nvarchar(10)", nullable: true),
                    ParentId = table.Column<Guid>(nullable: true),
                    OrderSort = table.Column<int>(nullable: false, defaultValue: 0),
                    Icon = table.Column<string>(type: "nchar(10)", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1000)", nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false),
                    Type = table.Column<byte>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPermission", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    Name = table.Column<string>(type: "nvarchar(10)", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(10)", nullable: true),
                    Description = table.Column<string>(type: "nvarchar(1000)", nullable: true),
                    OrderSort = table.Column<int>(nullable: false, defaultValue: 0),
                    IsEnabled = table.Column<bool>(nullable: false, defaultValue: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysRole", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysRolePermissionMapping",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    RoleId = table.Column<Guid>(nullable: false),
                    PermissionId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysRolePermissionMapping", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysUser",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    UserName = table.Column<string>(type: "nvarchar(10)", nullable: false),
                    AccountNumber = table.Column<string>(type: "nvarchar(10)", nullable: false),
                    Password = table.Column<string>(type: "nvarchar(36)", nullable: false),
                    State = table.Column<int>(nullable: false, defaultValue: 0),
                    Sex = table.Column<int>(nullable: false, defaultValue: 0),
                    Age = table.Column<int>(nullable: true),
                    Remarks = table.Column<string>(type: "nvarchar(1000)", nullable: true),
                    Icon = table.Column<string>(type: "nchar(100)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysUser", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "SysUserRoleMapping",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime", nullable: false, defaultValueSql: "GETDATE()"),
                    CreateUserId = table.Column<Guid>(nullable: true),
                    ModifiedUserId = table.Column<Guid>(nullable: true),
                    IsDelete = table.Column<bool>(nullable: false, defaultValue: false),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, defaultValueSql: "GETDATE()"),
                    UserId = table.Column<Guid>(nullable: false),
                    RoleId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysUserRoleMapping", x => x.Id);
                });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AuditLog");

            migrationBuilder.DropTable(
                name: "SysModule");

            migrationBuilder.DropTable(
                name: "SysPermission");

            migrationBuilder.DropTable(
                name: "SysRole");

            migrationBuilder.DropTable(
                name: "SysRolePermissionMapping");

            migrationBuilder.DropTable(
                name: "SysUser");

            migrationBuilder.DropTable(
                name: "SysUserRoleMapping");
        }
    }
}
